package com.hancai.web;

import com.github.pagehelper.PageInfo;
import com.hancai.model.TActivity;
import com.hancai.query.ActivityQuery;
import com.hancai.result.R;
import com.hancai.service.ActivityService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 涵菜
 * @version 1.0
 */
@RestController
public class ActivityController {
    @Resource
    private ActivityService activityService;
    /**
     * 活动列表分页查询
     */
    @GetMapping(value="/api/activities")
    public R activityPage(@RequestParam(value="current",required = false)Integer current, ActivityQuery activityQuery){
        if(current==null){
            current=1;
        }
        PageInfo<TActivity>pageInfo=activityService.getActivityByPage(current,activityQuery);
        return R.OK(pageInfo);
    }

    @GetMapping(value = "/api/activity/{id}")
    public R activityDetail(@PathVariable(value = "id")Integer id){
        TActivity activity=activityService.getActivityById(id);
        return R.OK(activity);
    }

}
